#ifndef SSL_CONTEXT_H
#define SSL_CONTEXT_H

#include <openssl/ssl.h>

#include "../../../tcp/code/utility/Noncopyable.h"
#include "./SslConfig.h"

class SslContext : Noncopyable
{
public:
    explicit SslContext(const SslConfig &config) : config_(config), ctx_(nullptr) {}
    ~SslContext()
    {
        if (this->ctx_)
        {
            ::SSL_CTX_free(this->ctx_);
        }
    }

    bool init();
    SSL_CTX *getContext()
    {
        return this->ctx_;
    }

private:
    static void handleError(const char *msg);
    bool loadCertificatesAndPrivateKey();
    bool setupProtocolVersionAndCipherList();
    void setupSessionCacheSizeAndTimeout();

private:
    SslConfig config_;
    SSL_CTX *ctx_;
};

#endif // SSL_CONTEXT_H